<?php

/**
 * album actions.
 *
 * @package    wills
 * @subpackage album
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class albumActions extends sfActions
{
  public function executeIndex(sfWebRequest $request)
  {
    $this->pager = new sfDoctrinePager(
      'Album',
      sfConfig::get('app_per_page_album')
    );
    $this->pager->setQuery(Doctrine::getTable('Album')->createQuery('a'));
    $this->pager->setPage($request->getParameter('page', 1));
    $this->pager->init();

    $this->albums = $this->pager->getResults();
  }

  public function executeShow(sfWebRequest $request)
  {
    $this->albumName = Doctrine::getTable('Album')->findOneById($request->getParameter('id'));
    $this->album = Doctrine::getTable('Album')->find(array($request->getParameter('id')));

    $this->forward404Unless($this->album);
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $album = $form->save();

      $this->redirect('album/edit?id='.$album->getId());
    }
  }
}
